package edu.ynu.se.xiecheng.achitectureclass.controller;


import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import edu.ynu.se.xiecheng.achitectureclass.domain.Result;
import edu.ynu.se.xiecheng.achitectureclass.dao.CustomerDao;
import edu.ynu.se.xiecheng.achitectureclass.domain.entity.Customer;
import edu.ynu.se.xiecheng.achitectureclass.domain.dto.AddOrderDto;
import edu.ynu.se.xiecheng.achitectureclass.service.CustomerService;
import edu.ynu.se.xiecheng.achitectureclass.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "顾客控制器")
@RestController
@RequestMapping("/customer")
public class CustomerController extends LogicController<CustomerService, CustomerDao, Customer, Long> {

    @Resource
    OrderService orderService;

    public CustomerController(CustomerService ls) {
        super(ls);
    }

    @GetMapping("/getOrder")
    @ApiOperation("获得订单")
    public Result getOrder(Long customerId, Long shopId) {
        return getService().getOrder(customerId, shopId);
    }

    @PostMapping("/addOrder")
    @ApiOperation("新增订单")
    public Result addOrder(@RequestBody AddOrderDto orderDto) {
        return getService().addOrder(
                orderDto.getCustomerId(),
                orderDto.getShopId(),
                orderDto.getTotalPrice(),
                orderDto.getList()
        );
    }

    @GetMapping("/pay")
    @ApiOperation("支付订单")
    public Result payOrder(Long orderId) {
        return getService().payState(orderId);
    }

    @GetMapping("/deleteOrder")
    @ApiOperation("删除订单")
    public Result deleteOrder(Long orderId) {
        orderService.DELETE(orderId);
        return new Result(true, "删除成功");
    }

    @GetMapping("/getAllOrder")
    @ApiOperation("获取所有订单")
    public Result getAllOrder(Long customerId) {
        return getService().getAllOrder(customerId);
    }

    @GetMapping("/getFinshOrder")
    @ApiOperation("获取已支付订单")
    public Result getFinshOrder(Long customerId) {
        return getService().getOrderByPayState(customerId, 1);
    }

    @GetMapping("/getNoFinshOrder")
    @ApiOperation("获取未支付订单")
    public Result getNoFinshOrder(Long customerId) {
        return getService().getOrderByPayState(customerId, 0);
    }

    @GetMapping("/getOrderById")
    @ApiOperation("根据orderid查询订单")
    public Result getOrderById(Long orderId) {
        return getService().getOrderById(orderId);
    }

    @GetMapping("/getRefuseOrder")
    @ApiOperation("获取退款订单")
    public Result getRefuseOrder(Long customerId) {
        return getService().getOrderByState(customerId, 2, 1);
    }
}
